<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
        <h2><c:out value="${player1.lastName}"/> vs. <c:out value="${player2.lastName}"/></h2>
        <div class="colmask threecol">
            <div class="colmid">
                <div class="colleft">
                    <div class="col1" >
                        <h1>Rounds</h1>
                        <table class="default">
                            <tr>
                                <th>Round</th>
                                <th>Pl1 : Pl2</th>
                                    <c:if test='<%= (Boolean.parseBoolean(session.getAttribute("isAdmin").toString()))%>' >
                                    <th>Edit</th>
                                    <th>Remove</th>
                                    </c:if>
                            </tr>
                            <c:forEach  items="${rounds}" var="round">
                                <tr>
                                    <td><c:out value="${round.sequenceNumber}"/></td>
                                    <td><c:out value="${round.pointCount1}"/> - <c:out value="${round.pointCount2}"/></td>
                                    <c:if test='<%= (Boolean.parseBoolean(session.getAttribute("isAdmin").toString()))%>' >
                                        <td><a href="<c:url value="/admin/round/edit?matchId=${match.id}&seqNum=${round.sequenceNumber}" />"><img src="<c:url value="/resources/img/edit-icon.gif" />" width="16" height="16" alt="edit" /></a></td>
                                        <td><a href="<c:url value="/admin/round/remove?matchId=${match.id}&seqNum=${round.sequenceNumber}" />"><img src="<c:url value="/resources/img/remove-icon.gif" />" width="16" height="16" alt="remove" /></a></td>
                                            </c:if>
                                </tr>
                            </c:forEach>
                        </table>
                        <c:if test='<%= (Boolean.parseBoolean(session.getAttribute("isAdmin").toString()))%>' >
                            <br/>
                            <div class="buttons">
                                <a href="<c:url value="/admin/round/add?matchId=${match.id}" />" class="button add">Add a new round</a>
                            </div>
                        </c:if>
                    </div>
                    <div class="col2">
                        <h1>Basic info</h1>
                        <table class="simple">
                            <tr>
                                <td>Match</td>
                                <td><c:out value="${player1.lastName}"/> vs. <c:out value="${player2.lastName}"/></td>
                            </tr>
                            <tr>
                                <td>Date and Time</td>
                                <td><c:out value="${match.dateAndTime}"/></td>
                            </tr>
                            <tr>
                                <td>Season</td>
                                <td>
                                    <c:out value="${season.name}"/>
                                    <c:out value="${season.startDate}"/> - <c:out value="${season.endDate}"/>
                                </td>
                            </tr>
                        </table>
                    </div>
                    <div class="col3">
                        <h1>Complaints</h1>
                        <table class="default">
                            <tr>
                                <th>Name</th>
                                <th>Detail</th>
                                    <c:if test='<%= (Boolean.parseBoolean(session.getAttribute("isAdmin").toString()))%>' >
                                    <th>Remove</th>
                                    </c:if>
                            </tr>
                            <c:forEach  items="${complaints}" var="complaint">
                                <tr>
                                    <td><c:out value="${complaint.name}"/></td>

                                    <td><a href="<c:url value="/admin/complaint/detail?id=${complaint.id}" />"><img src="<c:url value="/resources/img/detail-icon.png" />" width="16" height="16" alt="detail" /></a></td>
                                            <c:if test='<%= (Boolean.parseBoolean(session.getAttribute("isAdmin").toString()))%>' >
                                        <td><a href="<c:url value="/admin/complaint/remove?id=${complaint.id}" />"><img src="<c:url value="/resources/img/remove-icon.gif" />" width="16" height="16" alt="remove" /></a></td>
                                            </c:if>
                                </tr>
                            </c:forEach>
                        </table>

						<br/>
						<div class="buttons">
							<a href="<c:url value="/admin/complaint/edit?matchId=${match.id}" />" class="button add">Add a complaint to this match</a>
						</div>
                    </div>
                </div>
            </div>
        </div>
        <div id="footer">
            <br>
                <br>
                <form:errors path="*"/>
            
            <h1>Add comments:</h1>
			<form:form modelAttribute="comment" method="post" action="/admin/match/addComment" >
				<table>
					<tr>
						<td style="color: gray;" >Name (optional)</td>
						<td style="width: 170px;"><form:input path="name" /></td>
					</tr>
					<tr>
						<td style="color: gray;" >Text</td>
						<td><form:textarea cols="60" rows="5" path="text" /></td>
					</tr>
				</table>
				<input type="submit" value="Add" />
			</form:form>	
            <br/>
            <h1>Comments:</h1>
            <c:forEach  items="${comments}" var="comment">
                <div id="twomaincontainer">
                    <div id="twocontentwrapper">
                        <c:out value="${comment.name}"/> (<c:out value="${comment.timestamp}"/>)
                        <br/>
                        <textarea cols="60" rows="3" readonly="true" >
                            <c:out value="${comment.text}"/>
                        </textarea>
                    </div>
                </div>
            </c:forEach>
        </div>
    </body>
</html>
